#![allow(unused_assignments)]
use sha1::{Sha1, Digest};

use crate::domain::error::Result;


pub async fn verify_password(password: String, salt: String, encrypt_password: String) -> Result<bool> {
	let password_check = multi_sha1(password,salt,3);
	Ok(encrypt_password==password_check)
}


pub fn mysha1(data:Vec<u8>) -> Vec<u8>{
	let mut h = Sha1::new();
	h.update(data);
	let result = h.finalize();
	result.to_vec()
}

pub fn multi_sha1(password:String, salt:String, iter:i32)-> String{
	let mut b:Vec<u8> = password.as_bytes().to_vec();
	let mut s:Vec<u8>  = salt.as_bytes().to_vec();
	s.append(&mut b);
	let mut h = Sha1::new();
	h.update(s);
	let mut result:Vec<u8> = h.finalize().to_vec();
	h = Sha1::new();
	for _i in 1 .. iter {
		result = mysha1(result);
	}
	hex::encode(result.clone())
}
